<script setup lang="ts">
import {onMounted, ref} from "vue";
import {reqHospitalLevelAndRegion} from '@/api/home/index.ts'
import type {HospitalLevelAndRegionResponseData,HospitalLevelAndRegionDataArr} from '@/api/home/type.ts'
onMounted(()=>{
  getRegion()
})
//控制医院等级的高亮响应式显示
let activeFlag = ref('')
let $emit = defineEmits(['getRegion'])
const changeRegion=(value:string)=>{
  activeFlag.value=value
  $emit('getRegion',value)
}
// 定义一个数组存储医院等级数据
let regionArr = ref<HospitalLevelAndRegionDataArr>([])
const getRegion=async ()=>{
  let result:HospitalLevelAndRegionResponseData= await reqHospitalLevelAndRegion('Beijin')
  if(result.code==200){
    regionArr.value=result.data
  }
  // console.log(result)
}
</script>

<template>
  <div class="region">
    <div class="content">
      <div class="l">地区：</div>
      <ul class="area">
        <li class="active" :class="{active:activeFlag===''}" @click="changeRegion('')">全部</li>
        <li v-for="item in regionArr" :class="{active:activeFlag===item.value}" @click="changeRegion(item.value)" v-bind:key="item.id">{{item.name}}</li>
      </ul>
    </div>
  </div>
</template>

<style scoped lang="scss">
.region{
  color: #7f7f7f;
  .content{
    display: flex;
    .l{
      margin-right: 10px;
      width: 52px;
    }
    .area{
      display: flex;
      flex-wrap: wrap;
      li{
        margin-right: 10px;
        margin-bottom: 10px;
        &.active{
          color:#55a6fe;
        }
      }
      li:hover{
        color:#55a6fe;
        cursor:pointer;
      }
    }
  }
}
</style>